package com.magic.uschat.bean;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.newim.core.command.f;

import com.lidroid.xutils.db.annotation.Check;
import com.lidroid.xutils.db.annotation.Column;
import com.lidroid.xutils.db.annotation.Finder;
import com.lidroid.xutils.db.annotation.Foreign;
import com.lidroid.xutils.db.annotation.Id;
import com.lidroid.xutils.db.annotation.NoAutoIncrement;
import com.lidroid.xutils.db.annotation.Table;
import com.lidroid.xutils.db.annotation.Transient;
import com.lidroid.xutils.db.sqlite.FinderLazyLoader;


@Table(name="dbFriends")
public class DbFriends {
	@Id
	private int id;
	@Column(column="comment")
	private String comment;
	@Column(column="sortLetter")
	private String sortLetter;
	@Transient
	private DbUser  owenr;
	@Foreign(column="friendId",foreign="objectId")
	private DbUser friend;
	@Column(column="owenrId")
	private String owenrId;
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public String getSortLetter() {
		return sortLetter;
	}

	public void setSortLetter(String sortLetter) {
		this.sortLetter = sortLetter;
	}

	public DbUser getOwenr() {
		return owenr;
	}

	public void setOwenr(DbUser owenr) {
		this.owenr = owenr;
	}

	public DbUser getFriend() {
		return friend;
	}

	public void setFriend(DbUser friend) {
		this.friend = friend;
	}

	public String getOwenrId() {
		return owenrId;
	}

	public void setOwenrId(String owenrId) {
		this.owenrId = owenrId;
	}
	
	public DbFriends(){}

	public DbFriends(Friends friend,String owenrId){
		this.comment = friend.getComment();
		this.sortLetter = friend.getSortLetter();
		this.owenrId = owenrId;
		this.friend = new DbUser(friend.getFriend());
		
	}
	
	public Friends toFriends(){
		Friends f = new Friends();
		f.setComment(comment);
		f.setSortLetter(sortLetter);
		if (friend!=null) {
			f.setFriend(friend.toUser());
		}
		return f;
	}
	
	public static List<Friends> toFriendList(List<DbFriends> dbFriendList){
		List<Friends> friends = new ArrayList<Friends>();
		for(int i=0;i<dbFriendList.size();i++){
			friends.add(dbFriendList.get(i).toFriends());
		}
		return friends;
	}
	
	public static List<DbFriends> getDbFriendList(List<Friends> friends,String owenrId){
		List<DbFriends> dbFriends = new ArrayList<DbFriends>();
		for(int i=0;i<friends.size();i++){
			dbFriends.add(new DbFriends(friends.get(i),owenrId));
		}
		return dbFriends;
	}
	
	public static List<DbUser> getDbUserList(List<Friends> friends){
		List<DbUser> dbUser = new ArrayList<DbUser>();
		for(int i=0;i<friends.size();i++){
			dbUser.add(new DbUser(friends.get(i).getFriend()));
		}
		return dbUser;
	}
	
}
